<?php $this->_extends('_layouts/bocib_layout'); ?>

<?php $this->_block('content');?>

<div id="content">
    <h2>新闻信息</h2>
    <p class="jump"><a href="<?=url('bonewsnotice/addnews');?>">添加新闻 >></a></p>
    <p class="jump"><a href="<?=url('newsnotice/index');?>">跳转至前台查看已添加/更新的新闻 >></a></p>
    <ul class="news-ctgry">
        <li>按分类查看:</li>
        <?php foreach(NewsCategory::find('haschild != 1')->all()->query() as $newsCtgry) { ?>
        <li><a href="<?=url('bonewsnotice/listnews', array('ctgry_id'=>$newsCtgry->id));?>"><?=$newsCtgry->category;?></a></li>
        <?php } ?>
    </ul>

    <div id="searchResult-panel">
        <form method="get" action="<?=url('bonewsnotice/listnews');?>">
            <div>
                <label>按标题与内容搜索新闻</label>
                <input type="text" name="qtitlebody" value="" />
                <input type="submit" value="搜索新闻" />
            </div>
        </form>

        <ul>
			<li><b>标签：</b></li>
			<li>新闻通知标签：
			<?php foreach(Tag::find('category = ?', '新闻通知')->all()->query() as $tag) { ?>
				<a href="<?=url('bonewsnotice/listnews', array('tag'=>$tag->tag));?>"><?=$tag->tag;?></a>
            <?php } ?>
			</li> 
			<li>国际交流标签：
			<?php foreach(Tag::find('category = ?', '国际交流')->all()->query() as $tag) { ?>
				<a href="<?=url('bonewsnotice/listnews', array('tag'=>$tag->tag));?>"><?=$tag->tag;?></a>
            <?php } ?>
			</li> 
			<li>创新实践标签：
			<?php foreach(Tag::find('category = ?', '创新实践')->all()->query() as $tag) { ?>
				<a href="<?=url('bonewsnotice/listnews', array('tag'=>$tag->tag));?>"><?=$tag->tag;?></a>
            <?php } ?>
			</li> 
        </ul>

        <?php if(isset($_GET['qtitlebody'])) { ?>
        <p class="qresult">
            <b>搜索结果：共有 <?=$qtitlebodyrecords->count();?> 条记录符合关键字“<?=$_GET['qtitlebody'];?>”</b>
        </p>
        <ul>
            <?php if(!$qtitlebodyrecords->isEmpty()) { ?>
                <?php foreach($qtitlebodyrecords as $key => $qtr) { ?>
                <li>
                <?=$key+1;?>. <?=$qtr->title;?>
                <?php if(!$qtr->attachments->isEmpty()) { ?>
                    <img src="misc/with-attachment.gif" alt="attachmentMark" />
                <?php } ?>
                (<a href="<?=url('bonewsnotice/editnews', array('news_id'=>$qtr->news_id));?>" target="_blank">更新</a>)
                (<a href="<?=url('bonewsnotice/deletenews', array('news_id'=>$qtr->news_id));?>">删除</a>)</li>
                <?php } ?>
            <?php } else { ?>
            <li>抱歉，没有相关新闻，请尝试更换关键字再试一次</li>
            <li>或者您也可以 <a href="<?=url('newsnotice/index');?>">查看最新发布的一条新闻</a></li>
            <?php } ?>
        </ul>
        <?php } ?>

        <?php if(isset($_GET['tag'])) { ?>
        <p class="qresult">
            <b>搜索结果：共有 <?=$tagrecords->count();?> 条新闻符合<span style="text-decoration:underline;">标签“<a href="#"><?=$_GET['tag'];?></a>”</span></b>
        </p>
        <ul>
            <?php if(!$tagrecords->isEmpty()) { ?>
                <?php foreach($tagrecords as $key => $tr) { ?>
                <li><?=$key+1;?>. <?=$tr->title;?>
                <?php if(!$tr->attachments->isEmpty()) { ?>
                <img src="misc/with-attachment.gif" alt="attachmentMark" />
                <?php } ?>
                (<a href="<?=url('bonewsnotice/editnews', array('news_id'=>$tr->news_id));?>" target="_blank">更新</a>)
                (<a href="<?=url('bonewsnotice/deletenews', array('news_id'=>$tr->news_id));?>">删除</a>)</li>
                <?php } ?>
            <?php } else { ?>
            <li>抱歉，没有相关新闻，请尝试更换关键字再试一次</li>
            <li>或者您也可以 <a href="<?=url('newsnotice/index');?>">查看最新发布的一条新闻</a></li>
            <?php } ?>
        </ul>
        <?php } ?>
    </div><!-- /searchResult-panel -->

    <div class="pagenav">
        <?php $this->_control('pagination', 'pgnv-n1', array('pagination' => $newspg)); ?>
    </div>

    <table>
        <tr>
            <th class="news_id">id</th>
            <th class="title">标题</th>
            <th class="ctgry_id">分类</th>
            <th class="publisher">发布人</th>
            <th class="hasattachment">附件</th>
            <th class="tag">标签</th>
            <th class="updated">发布时间</th>
            <th class="edit">更新</th>
            <th class="delete">删除</th>
        </tr>
        <?php foreach($news as $n) { ?>
        <tr>
            <td><?=$n->news_id;?></td>
            <td><?=$n->title;?></td>
            <td><?=$n->category->category;?></td>
            <td><?=$n->publisher;?></td>
            <td>
            <?php if(!$n->attachments->isEmpty()) { ?>
            <img src="misc/with-attachment.gif" alt="attachmentMark" />
            <?php } else { ?>
            &nbsp;
            <?php } ?>
            </td>
            <td><?=trim($n->tag, ',');?></td>
            <td><?=$n->adate;?></td>
            <td><a href="<?=url('bonewsnotice/editnews', array('news_id'=>$n->news_id));?>" target="_blank">更新</a></td>
            <td><a href="<?=url('bonewsnotice/deletenews', array('news_id'=>$n->news_id));?>">删除</a></td>
        </tr>
        <?php } ?>
    </table>

    <div class="pagenav">
        <?php $this->_control('pagination', 'pgnv-n1', array('pagination' => $newspg)); ?>
    </div>
</div>
<?php $this->_endblock('content');?>